package learn.up.java1.quartz;

import java.util.Date;

import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

public class TriggerDetail {
	public static void main(String[] args) {
		Date d = new Date();
		System.out.println("currentTime  "+JobHello.sfd.format(d));
		
		JobDetail jd = JobBuilder.newJob(JobHello.class)
				.withIdentity("name", "john")
				.usingJobData("math",98).build();
		
//		获取当前时间三秒后的时间
		d.setTime(d.getTime()+3000);
		
//		设置在当前时间3秒后执行,6秒后停止执行
		Date endTime = new Date();
	    endTime.setTime(endTime.getTime()+3000);
		Trigger trigger = TriggerBuilder.newTrigger()
				.withIdentity("trigger","trigger-1")
				.usingJobData("age",23).startAt(d).endAt(endTime)
				.withSchedule(SimpleScheduleBuilder.simpleSchedule()
						.withIntervalInSeconds(2).repeatForever()).build();
		SchedulerFactory sf  =  new StdSchedulerFactory();
		try {
			Scheduler schedule  =  sf.getScheduler();
			schedule.start();
			schedule.scheduleJob(jd,trigger);
		} catch (SchedulerException e) {
			e.printStackTrace();
		}
	}
}
